#define _CRT_SECURE_NO_WARNINGS 1
#include"game.h"
void menu()
{
	printf("*****************************************\n");
	printf("**************   1. paly   **************\n");
	printf("**************   0. exit   **************\n");
	printf("*****************************************\n");
}

void game()
{
	//数据存储，二维数组
	char board[ROW][COL] = { 0 };
	//棋盘:chessboard  行:row,列:column,defind声明的变量通常大写用来区分
	//符号的声明和函数定义放在game.h
					
	//初始化棋盘成空格
	init_board(board, ROW, COL);

	//打印棋盘
    print_board(board, ROW, COL);

//ret==什么，游戏就结束了
//玩家赢 - '*'
//电脑赢 - '#'
//平局   - 'g'
//继续   - 'r'
	//落子和判断输赢
	char ret = 0;
	while(1)
	{
		//玩家下棋:
		player_move(board, ROW, COL);
		print_board(board, ROW, COL);
		ret=is_win(board, ROW, COL);
		if (ret != 'r')
		{
			break;
		}
		//电脑下棋:
		computer_move(board, ROW, COL);
		print_board(board, ROW, COL);
		ret = is_win(board, ROW, COL);
		if (ret != 'r')
		{
			break;
		}
	}
	if (ret == '*')
	{
		printf("恭喜你赢了！\n");
	}
	else if (ret == '#')
	{
		printf("恭喜电脑赢了emm\n");
	}
	else
	{
		printf("平局 gg\n");
	}
}
int main()
{
	//随机数种子
	srand((unsigned int)time(NULL));

	int input = 0;
	do
	{
		menu();
			printf("请选择:");
		scanf("%d", &input);
		switch (input)
		{
		case 1:
			game();
			break;
		case 0:
			printf("退出游戏\n");
			break;
		default:
			printf("输入错误;重新输入:\n");
			break;
		}
	} while (input);
	return 0;
}